//
//  sstTcp.h
//  OpensslTest
//
//  Created by jiahua on 16/3/30.
//  Copyright © 2016年 secsmarts. All rights reserved.
//
//  此类用来进行TCP的连接建立、发送、接收数据的处理
//

#import <Foundation/Foundation.h>
#import "GCDAsyncSocket.h"

@class sstTcp;

/**
 *  定义Tcp错误代理
 */
@protocol SSTTcpErrorDelegate
@optional
/*
 *  TCP错误处理代理
 *
 *  @param tcp
 *  @param Tag 错误代码
 */
-(void)sstTcpError:(sstTcp*) tcp withTag:(NSInteger)tag;
@end
/**
 *  定义UDP信息通知代理，主要为测试使用，可以不实现此代理
 */
@protocol SSTTcpInfoNotifyDelegate
@optional
/**
 *  UDP的信息处理代理
 *
 *  @param udp
 *  @param info
 */
-(void)sstTcpInfoNotify:(sstTcp*)udp withInfo: (NSString *)info;
@end
/**
 *  定义sstTcp
 */
@interface sstTcp : GCDAsyncSocket
/**
 *  错误代理
 */
@property(nonatomic, retain)id<SSTTcpErrorDelegate>tcpErrorDelegate;
/**
 * 通知代理
 */
@property(nonatomic, retain) id<SSTTcpInfoNotifyDelegate> tcpInfoNotifyDelegate;
//
// TCP6种不同的建立连接方式
//
-(BOOL)connectToAddress:(NSData *)remoteAddr error:(NSError *__autoreleasing *)errPtr;
-(BOOL)connectToAddress:(NSData *)remoteAddr withTimeout:(NSTimeInterval)timeout error:(NSError *__autoreleasing *)errPtr;
-(BOOL)connectToAddress:(NSData *)remoteAddr viaInterface:(NSString *)interface withTimeout:(NSTimeInterval)timeout error:(NSError *__autoreleasing *)errPtr;
-(BOOL)connectToHost:(NSString *)host onPort:(uint16_t)port error:(NSError *__autoreleasing *)errPtr;
-(BOOL)connectToHost:(NSString *)host onPort:(uint16_t)port withTimeout:(NSTimeInterval)timeout error:(NSError *__autoreleasing *)errPtr;
-(BOOL)connectToHost:(NSString *)host onPort:(uint16_t)port viaInterface:(NSString *)interface withTimeout:(NSTimeInterval)timeout error:(NSError *__autoreleasing *)errPtr;
//关闭连接
-(void)disconnect;
/**
 *  TCP建立连接后发送数据
 *
 *  @param data
 *  @param timeout
 *  @param tag
 */
-(void)writeData:(NSData *)data withTimeout:(NSTimeInterval)timeout tag:(long)tag;

/**
 *  TCP建立连接后接收数据
 *
 *  @param result
 *
 *  @return 返回解密后的数据
 */
-(NSData *)handleReadData:(NSData *)result;
@end
